package de.jmetroid.tiles;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;

public class TileFactory {

  private static final Mesh BOX_MESH = new Box(Vector3f.ZERO, 0.5f, 0.5f, 0.5f);
  private final AssetManager assetManager;

  public TileFactory(final AssetManager theAssetManager) {
    assetManager = theAssetManager;
  }

//  public void createTile(final Node theAttachTo, final PhysicsSpace thePhysicsSpace, final Vector3f thePosition) {
//    Tile tile = new Tile(BOX_MESH);
//    final Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
//    material.setTexture("ColorMap", assetManager.loadTexture("de/jmetroid/tiles/crateria-floor.png"));
//    tile.setMaterial(material);
//    tile.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(1f, 1f, 1f)), 0));
//    tile.setLocalTranslation(thePosition.x, thePosition.y, thePosition.z);
//    theAttachTo.attachChild(tile);
//    thePhysicsSpace.add(tile);
//  }

  public void createTile(Vector3f theLocalTranslation, Node theNodeToAttach, PhysicsSpace thePhysicsSpace) {
    Tile tile = new Tile(BOX_MESH);
    final Material material = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
    material.setTexture("ColorMap", assetManager.loadTexture("de/jmetroid/tiles/crateria-floor.png"));
    tile.setMaterial(material);
    tile.setLocalTranslation(theLocalTranslation);
    tile.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(1f, 1f, 1f)), 0));
    theNodeToAttach.attachChild(tile);
    thePhysicsSpace.add(tile);
  }

}
